package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.dto.SysRoleDTO;
import com.hotelvip.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户权限模块
 * @author Lzh
 * @date 2020/12/22 9:45
 */
@RestController
@RequestMapping("sys/role")
@Api(basePath = "sys/role",tags = "用户权限模块")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation(value = "查询权限", httpMethod = "GET")
    @GetMapping("/doFindRoles")
    public JSONResult doFindRoles() {
        return JSONResult.ok(sysRoleService.findRoles());
    }

    @ApiOperation(value = "根据id查询权限",httpMethod = "GET")
    @GetMapping("/doFindObjectById")
    public JSONResult doFindObjectById(Integer id) {
        return JSONResult.ok(sysRoleService.findById(id));
    }
    @ApiOperation(value = "更新权限信息",httpMethod = "PUT")
    @PutMapping("/doUpdateObject")
    public JSONResult doUpdateObject(@RequestBody SysRoleDTO entity) {
        sysRoleService.updateObject(entity.getSysRole(), entity.getMenuIds());
        return JSONResult.ok("更新成功");
    }

    @ApiOperation(value = "添加权限",httpMethod = "POST")
    @PostMapping("/doSaveObject")
    public JSONResult doSaveObject(@RequestBody SysRoleDTO entity) {
        sysRoleService.saveObject(entity.getSysRole(), entity.getMenuIds());
        return JSONResult.ok("添加成功");
    }

    @ApiOperation(value = "查询权限列表",httpMethod = "GET")
    @GetMapping("/doFindPageObjects")
    public JSONResult doFindPageObjects(String name,Long pageCurrent) {
        return JSONResult.ok(sysRoleService.findPageObjects(name, pageCurrent));
    }

}
